﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ScoreMS.Model;

namespace ScoreMS.BLL
{
    public class Score_finalBS
    {
        /// <summary>
        /// 获取最终的成绩Model列表，（按班级开设的课程）
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        static public List<Score_final> GetScore_finalList(string course_id, string class_id)
        {
            using (scoremsdbEntities db = new scoremsdbEntities())
            {
                var scores = db.score.Where(x => x.course_id == course_id && x.student.class_id == class_id);
                var score_others = db.score_other.Where(x => x.course_id == course_id && x.student.class_id == class_id);
                var list = scores.Join(score_others, x=>x.student_id,y=>y.student_id, (x,y)=>new {x.student_id, x.student.student_sex, x.student.student_name, x.course_id, x.score_exam, y.score_other_task, y.score_other_attendance, y.score_other_homework});
                var ret = new List<Score_final>();
                foreach(var c in list)
                {
                    Score_final model = new Score_final();
                    model.course_id = c.course_id;
                    model.score_exam = c.score_exam;
                    model.student_id = c.student_id;
                    model.student_sex = c.student_sex;
                    model.student_name = c.student_name;
                    model.score_other = (int)(c.score_other_attendance * 0.1 + c.score_other_homework * 0.1 + c.score_other_task * 0.3) * 2;
                    model.score_final = (int)(c.score_other_attendance * 0.1 + c.score_other_homework * 0.1 + c.score_other_task * 0.3) + (int)(c.score_exam * 0.5);
                    ret.Add(model);
                }
                return ret;
            }
        }
    }
}
